package com.gzsxy.esjy.request;

import io.netty.handler.codec.http.multipart.FileUpload;
import io.netty.handler.codec.http.multipart.HttpPostRequestDecoder;

import java.util.ArrayList;
import java.util.List;

/**
 * 文件上传类
 * @author zhangxiaolong
 * @date 2022/7/6 9:36
 */
public interface MultipartHttpRequest extends HttpServletRequest{

	/**
	 * 获取上传文件
	 * @param name
	 * @return
	 */
	public FileUpload getFile(String name) ;
	
	/**
	 * 获取decoder
	 * @return
	 */
	public HttpPostRequestDecoder getPostRequestDecoder() ;
	
	
	@SuppressWarnings("unchecked")
	default public void addParam(String key,Object param) {
		Object value = getParam(key);
		if(value != null) {
			if(value instanceof List<?>) {
				((List<Object>)value).add(param) ;
				return ;
			}else {
				List<Object> list = new ArrayList<Object>() ;
				list.add(value) ;
				list.add(param);
				getParams().put(key, list) ;
				return ;
			}
		}
		getParams().put(key, param) ;
	}
}
